#include <Windows.h>

HANDLE g_Output, g_Input;

/// Console
void StartConsole(short width = 80, short height = 25, char * ConsoleName = "Console Window") {
    char buffer[255];
    COORD cCoord;
    SMALL_RECT sRect;
            
    AllocConsole();
    g_Output = GetStdHandle(STD_OUTPUT_HANDLE);
    g_Input = GetStdHandle(STD_INPUT_HANDLE);
    CharToOem(ConsoleName, (char*)&buffer);
    SetConsoleTitle(buffer);
    cCoord.X = width;
    cCoord.Y = height;
    SetConsoleScreenBufferSize(g_Output,cCoord);
    sRect.Left = 0;
    sRect.Right = width - 1;
    sRect.Top = 0;
    sRect.Bottom = height - 1;
    SetConsoleWindowInfo(g_Output, true, &sRect);
}

void EndConsole(void) {
    FreeConsole();
}

void Out(char * _text) {
    unsigned long num;
    char buffer[255];
 
    CharToOem(_text, (char*)&buffer);
    WriteConsole(g_Output, buffer, lstrlen(buffer), &num, NULL);
}

void Out(int _text) {
    unsigned long num;
    char buffer[255];
 
    wsprintf(buffer, "%i", _text);
    WriteConsole(g_Output, buffer, lstrlen(buffer), &num, NULL);
}

void NewLine(void) {
    unsigned long num;
 
    WriteConsole(g_Output, "\n\r", 2, &num, NULL);
}

int main() {
	int i;
	HMODULE hModule = GetModuleHandle(NULL);

	StartConsole();
	Out("Stack address: ");
	Out((int)&i);
	NewLine();
	Out("Module: ");
	Out((int)hModule);
	NewLine();
	EndConsole();

	return 0;
}